<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>系统模块信息</title>
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<script type="text/javascript">
	var path = "${path}";
	var shStatus = new Array("停用", "启用");
	var params = new Object();

    $(function() {

        $('#tt').treegrid({
            url : '',
            idField : 'menuCode',
            treeField : 'menuName',
            toolbar : $('#tb'),
            columns : [ [ {
                title : 'menuId',
                field : 'menuId',
                width : 180,
                hidden : true
            }, {
                field : 'menuName',
                title : '模块名称',
                width : 180
            }, {
                field : 'menuCode',
                title : '模块代码',
                width : 60,
                align : 'right'
            }, {
                field : 'parentMenuCode',
                title : '上级模块代码',
                width : 90
            }, {
                field : 'menuDescription',
                halign: 'center',
                title : '模块简称',
                width : 120
            }, {
                field : 'menuNum',
                title : '模块序号',
                width : 60
            }, {
                field : 'menuType',
                title : '模块类型',
                width : 60,
                align : 'right'
            }, {
                field : 'menuUrl',
                title : '模块 URL',
                width : 180
            }, {
                field : 'moduleIcon',
                title : '模块图标',
                width : 80
            }, {
                field : 'validMark',
                title : '状态',
                width : 60,
                align : 'right',
                formatter : function(value, row, index) {
                    return shStatus[value];
                }
            } ] ]
        });
        var grid = $("#tt");
        var url = path + "/system/module/queryByList";
        initTreegrid(grid, params, url);
        var grid_options = $("#tt").datagrid("options");
        grid_options.onDblClickRow = function(rowIndex, rowData) {
            btnEditNodeByGrid();
        }
    });
    
	//查询
	function btnQuery() {
		params.menuName = $("#menuName").val();
		var grid = $("#tt");
		var url = path + "/system/module/queryByList";
		initTreegrid(grid, params, url);
	}

	//增加模块
	function btnAddNode() {
		layer.open({
			type : 2,
            title: ['系统模块 - 添加','background: #38acff;'],
			shadeClose : false,
			shade : 0.6,
			area : [ '710px', '310px' ],
			content : '${path}/system/module/toAdd' //iframe的url
		});
	}

	//修改模块
	function btnEditNodeByGrid() {
		var rows = $('#tt').datagrid('getSelected');
		if (rows == null) {
			//$.messager.alert("友情提醒", "请选一个系统模块！", "info");
			$.alert("pick", "info", "系统模块");
			return;
		}
		layer.open({
			type : 2,
            title: ['系统模块 - 修改','background: #38acff;'],
			shadeClose : true,
			shade : 0.6,
			area : [ '710px', '310px' ],
			content : '${path}/system/module/toUpdate' //iframe的url
		});

	}

	//删除模块
	function btnDelNodeByGrid() {
		var rows = $('#tt').datagrid('getSelections');
		if (rows.length == 0) {
			//$.messager.alert("友情提醒", "请先选择系统模块信息！", "info");
			$.alert("pick", "info", "系统模块");
			return;
		}
		var rowData = rows[0];
		var param = new Object();
		param.menuId = rowData.menuId;
		param.menuCode = rowData.menuCode;
        param.originalCode = rowData.menuCode;
		$.messager.alert("问题", "请确认是否要删除？","confirm", function () {
				$.ajax({
					type : "POST",
					url : path + '/system/module/delete',
					data : param,
					dataType : "json",
					async : false,
					success : function callback(data) {
						var analyMsg = data;
						if (analyMsg.code != "0000") {
							$.messager.alert('友情提醒', analyMsg.msg, 'info',
									function() {
									});

						} else {
							btnQuery();
						}
					},
					error : function(data, textstatus) {
						$.messager.alert('友情提醒', data.responseText, 'info',
								function() {
								});
					}
				});
		});

	}

	//启用禁用模块
	function btnYxbzNodeByGrid() {
		var rows = $('#tt').datagrid('getSelections');
		if (rows.length == 0) {
			//$.messager.alert("友情提醒", "请先选择模块信息！", "info");
			$.alert("pick", "info", "模块信息");
			return;
		}
		var rowData = rows[0];
		var param = new Object();
        param.menuId = rowData.menuId;
        param.menuCode = rowData.menuCode;
        param.originalCode = rowData.menuCode;
		param.validMark = rowData.validMark;
        param.parentMenuCode = rowData.parentMenuCode;
		var mess = "";
		if (param.validMark == "1") {
			mess = "停用后该模块将无法使用，是否停用？";
		} else {
			mess = "是否启用";
		}
		$.messager.alert("问题", mess,"confirm", function() {
				$.ajax({
					type : "POST",
					url : path + '/system/module/updateValidMark',
					data : param,
					dataType : "json",
					async : false,
					success : function callback(data) {
						var analyMsg = data;
						if (analyMsg.code != "0000") {
							$.messager.alert('友情提醒', analyMsg.msg, 'error',
									function() {
									});
						} else {
							btnQuery();
						}
					}
				});
		});

	}

	//获取数据初始化表格所需数据
	function initTreegrid(grid, params, url) {
		$.ajax({
			type : "POST",
			url : url,
			data : params,
			dataType : "json",
			success : function callback(data) {
				var analyMsg = data;
                grid.treegrid('loadData', analyMsg.returnObject);
                grid.treegrid('collapseAll');
//				if (analyMsg.code != "0000") {
//					$.messager.alert("友情提醒", analyMsg.msg, "info", function() {
//					});
//                    return;
//				}
			},
//			error : function(data, textStatus) {
//				$.messager.alert("友情提醒", analyMsg.msg, "info", function() {
//
//				});
//				return;
//			}
		});
	}
</script>
</head>

<body>
	<div class="easyui-layout" fit="true">
		<div region="center" style="padding: 5px;" border="false">
			<div class="easyui-layout" fit="true" border="false">
				<div id="divNorth" region="north" title="查询条件" border="true"
					noheader="false"
					style="padding: 5px; height: 70px; background: none repeat scroll 0 0 #EFEFEF;">
					<table>
						<tr>
							<td>模块名称：</td>
							<td><input type="text" id="menuName" name="menuName" class = "query_input"
								style="width: 200px" /></td>
							<td><input class="search-btn-blue" style="margin-left:10px" type="button"
								onclick="btnQuery();" value="查询"></td>
						</tr>
					</table>
				</div>
				<div region="center" title="" border="false" noheader="true"
					style="padding: 5px 0 0 0;">
					<table id="tt" title="" border="false" fit="true" ></table>
				</div>
			</div>
		</div>
	</div>

	<div id="tb" style="padding: 1px; height: auto; display: none;">
		<div>
			<a id="btn_addNode_tb" href="javascript:void(0)"
				class="easyui-linkbutton" iconcls="icon-add" plain="false"
				onclick="btnAddNode()">新增</a> <a id="btn_editNode_tb"
				href="javascript:void(0)" class="easyui-linkbutton"
				iconcls="icon-edit" plain="false" onclick="btnEditNodeByGrid()">修改</a>
			<a id="btn_delNode_tb" href="javascript:void(0)"
				class="easyui-linkbutton" iconcls="icon-remove" plain="false"
				onclick="btnDelNodeByGrid()">删除</a> <a id="btn_qyNode_tb"
				href="javascript:void(0)" class="easyui-linkbutton"
				iconcls="icon-remove" plain="false" onclick="btnYxbzNodeByGrid()">启用/禁用</a>
		</div>
	</div>

</body>
</html>
